import TextItem from "./TextItem";
import HttpUtils from "../../common/utils/HttpUtils";
import touxiang from "../../../../imgs/touxiang.png";
import UserApi from "@module/userApi";

export default class PersonInfo extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            username: "",
            goodsinfo: [
                {
                    title: "待验收",
                    num: 2
                },
                {
                    title: "待结算",
                    num: 3
                },
                {
                    title: "待发货",
                    num: 5
                }
            ]
        };
    }

    componentDidMount() {
        if (global.hasLogin) {
            // this.getPersonInfo()
            this.userInfo();
        }
    }

    userInfo() {
        HttpUtils.buyerUserInfo()
            .then(res => {
                console.log(res);
                this.setState({
                    notDeliverOrderCount: res.notDeliverOrderCount, //待发货
                    notBanlanceOrderCount: res.notBanlanceOrderCount, //待结算
                    notTakeOrderCount: res.notTakeOrderCount, //待验收
                    settlingOrderCount: res.settlingOrderCount //结算中
                });
            })
            .catch(err => {
                console.log(err);
            });
    }

    getPersonInfo() {
        HttpUtils.getIdentity()
            .then(res => {
                console.log(res);
                this.setState({
                    username: res.user.realName
                });
            })
            .catch(err => {
                console.log(err);
            });
    }

    render() {
        const {
            goodsinfo,
            username,
            notDeliverOrderCount,
            notBanlanceOrderCount,
            notTakeOrderCount
        } = this.state;
        const { niceName } = UserApi.userInfo;


        return (
            <div className={"banner-header-person-info"}>
                <div className={"banner-header-person-info-headerimg"}>
                    <img src={touxiang} alt="" />
                </div>
                <p className={"banner-header-person-info-name"}>{niceName}</p>
                <div style={{ height: 28 }} />
                <div className={"banner-header-person-info-bottombox"}>
                    {goodsinfo.map((item, index) => (
                        <TextItem
                            key={index}
                            item={item}
                            index={index}
                            notDeliverOrderCount={notDeliverOrderCount || 0}
                            notBanlanceOrderCount={notBanlanceOrderCount || 0}
                            notTakeOrderCount={notTakeOrderCount || 0}
                        />
                    ))}
                </div>
            </div>
        );
    }
}
